package com.kpx.app.view;

import android.content.Context;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.kpx.app.R;
import com.kpx.app.wigdet.FlowLayout;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by congdy on 17/3/4.
 * 相关条目显示
 */

public class ViewComItem extends LinearLayout {
    @BindView(R.id.txt_title)
    TextView txtTitle;
    @BindView(R.id.txt_des)
    TextView txtDes;
    @BindView(R.id.flow_list)
    FlowLayout flowList;
    private Context context;

    public ViewComItem(Context context) {
        super(context);
        initView(context);
    }

    public ViewComItem(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        initView(context);
    }

    public ViewComItem(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView(context);
    }

    private void initView(Context context) {
        View v = View.inflate(context, R.layout.item_view_user_info, this);
        ButterKnife.bind(v);
        this.context = context;
    }

    public void setTitleStr(String title) {
        txtTitle.setText(title);
    }

    public void setDes(String des) {
        txtDes.setText(des);
    }

    public void setSigns(String des) {
        if (des == null || TextUtils.isEmpty(des)) return;
        String[] tags = des.split(",");
        if (tags.length > 0) {
            flowList.removeAllViews();
            flowList.setVisibility(View.VISIBLE);
            for (int i = 0; i < tags.length; i++) {
                View tagview = View.inflate(context, R.layout.tag_view, null);
                ((TextView) tagview.findViewById(R.id.txt)).setText(tags[i]);
                flowList.addView(tagview);
                ViewGroup.LayoutParams p = (ViewGroup.LayoutParams) tagview.getLayoutParams();
                p.width = LayoutParams.WRAP_CONTENT;
                p.height = LayoutParams.WRAP_CONTENT;
                tagview.setLayoutParams(p);
            }
        }
    }

    public void setClicLstener(OnClickListener lstener) {
        this.setOnClickListener(lstener);
    }
}
